<?php

/*
 * Action - Attack - Knight 5$
 *
 * Each other player discards down to 3 cards in hand.
 * Each other player reveals the top 2 cards of his deck, trashes one of them costing from 3 Coin to 6 Coin, and discards the rest. If a Knight is trashed by this, trash this card.
 */

class SirMichael extends Card implements iAction, iKingdom, iDarkAges, iKnight, iAttack {

    public function __construct() {
        parent::__construct("Sir Michael", 5);
        $this->undoPlay = false;
        $this->undoBuy = false;
    }

    public function getDescription() {
        return array(
            "Each other player discards down to 3 cards in hand.",
            "Each other player reveals the top 2 cards of his deck, trashes one of them costing from 3 Coin to 6 Coin, and discards the rest. If a Knight is trashed by this, trash this card.");
    }

    public function play(Game $game, $isRealCard) {
        $game->attack($this);
        
        $game->setPhase(Phase_Sleep);
        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize > 3) {

                $cards_to_discard = $playHandSize - 3;

                $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHandOther, $cards_to_discard, $cards_to_discard, null, "Choose $cards_to_discard cards to discard", $name, true);
            }
        }

        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {

            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, DiscardPile, $name);
            }

            ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($output), "discards " . sizeof($output) . " cards", $name);

            $game->setPhase(Phase_Sleep, $name);
        }

        $knight = new Knights();
        $knight->knightAttack($game, $this);
        $game->cardActionFinished();
    }

}

?>